package cn.enilu.guns.service.door;


import cn.enilu.guns.bean.entity.door.EventType;
import cn.enilu.guns.dao.cache.impl.EhcacheDao;
import cn.enilu.guns.dao.door.EventTypeRepository;

import cn.enilu.guns.service.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class EventTypeService extends BaseService<EventType,Long,EventTypeRepository>  {

    @Autowired
    private EhcacheDao ehcacheDao;

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private EventTypeRepository eventTypeRepository;


    public EventType findByEventCode(String eventCode) {
        return eventTypeRepository.findByEventCode(eventCode);
    }

    /**
     * 项目启动时，加载数据到ehcache
     */
    @PostConstruct
    public void initEventType() {
        List<EventType> eventTypeList = eventTypeRepository.findAll();
        for (EventType eventType:eventTypeList) {
            ehcacheDao.hset(EhcacheDao.EVENT_TYPE,eventType.getEventCode(), eventType);
        }
    }

}

